#include "Boss2ItemManager.h"

Boss2ItemManager::Boss2ItemManager()
{
	leftItems = new vector<Boss2ItemEntity*>();
	rightItems = new vector<Boss2ItemEntity*>();
	_count = 0;
	_time = 0;
}

void Boss2ItemManager::update(long time)
{
	_time++;
	if(_time > 400)
	{
		_count++;
		if(leftItems->size() < 5 && _count == DELAY_TIME)
		{
			_create();
		}
	}

	vector<Boss2ItemEntity*>::iterator it = leftItems->begin();
	for(; it != leftItems->end(); it++)
	{
		(*it)->update(time);
	}

	it = rightItems->begin();
	for(; it != rightItems->end(); it++)
	{
		(*it)->update(time);
	}
}

void Boss2ItemManager::draw(long time)
{
	vector<Boss2ItemEntity*>::iterator it = leftItems->begin();
	for(; it != leftItems->end(); it++)
	{
		(*it)->draw(time);
	}

	it = rightItems->begin();
	for(; it != rightItems->end(); it++)
	{
		(*it)->draw(time);
	}
}

void Boss2ItemManager::_create()
{
	_count = 0;
	int itemType = 0;
	vector<Boss2ItemEntity*>::iterator it = leftItems->begin();
	if(leftItems->size() == 0)
	{
		itemType = _ID_ARMY_BOSS_ITEM_TOP_2;
	}
	else
	{
		itemType = _ID_ARMY_BOSS_ITEM_2;
	}
	for(; it != leftItems->end(); it++)
	{
		(*it)->setMovingState(MovingState::STATE_MOVING_UP);
	}
	leftItems->push_back(new Boss2ItemEntity(itemType, _POSITION_BOSS_ITEM_LEFT_X, _POSITION_BOSS_ITEM_LEFT_Y));

	it = rightItems->begin();
	for(; it != rightItems->end(); it++)
	{
		(*it)->setMovingState(MovingState::STATE_MOVING_UP);
	}
	rightItems->push_back(new Boss2ItemEntity(itemType, _POSITION_BOSS_ITEM_RIGHT_X, _POSITION_BOSS_ITEM_RIGHT_Y));
}